home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 April: Mac OS SDK / Dev.CD Apr 99 SDK1.toast / Development Kits / Mac OS USB DDK / USB.h < prev   
Encoding:
C/C++ Source or Header  |  1999-02-15  |  33.0 KB  |  1,205 lines  |  [TEXT/MPS ]

  1. /*
  2.      File:        USB.h
  3.  
  4.      Contains:    Public API for USB Services Library (and associated components)
  5.  
  6.      Version:    
  7.  
  8. */
  9. #ifndef __USB__
  10. #define __USB__
  11.  
  12. #ifndef __MACTYPES__
  13. #include <MacTypes.h>
  14. #endif
  15. #ifndef __NAMEREGISTRY__
  16. #include <NameRegistry.h>
  17. #endif
  18. #ifndef __CODEFRAGMENTS__
  19. #include <CodeFragments.h>
  20. #endif
  21. #ifndef __DEVICES__
  22. #include <Devices.h>
  23. #endif
  24.  
  25.  
  26.  
  27. #if PRAGMA_ONCE
  28. #pragma once
  29. #endif
  30.  
  31. #ifdef __cplusplus
  32. extern "C" {
  33. #endif
  34.  
  35. #if PRAGMA_IMPORT
  36. #pragma import on
  37. #endif
  38.  
  39. #if PRAGMA_STRUCT_ALIGN
  40.     #pragma options align=mac68k
  41. #elif PRAGMA_STRUCT_PACKPUSH
  42.     #pragma pack(push, 2)
  43. #elif PRAGMA_STRUCT_PACK
  44.     #pragma pack(2)
  45. #endif
  46.  
  47. /* ************* Constants ************* */
  48. enum {
  49.     kUSBNoErr                    = 0,
  50.     kUSBNoTran                    = 0,
  51.     kUSBNoDelay                    = 0,
  52.     kUSBPending                    = 1,                            /* */
  53.                                                                 /* USB assigned error numbers in range -6900 .. -6999 */
  54.     kUSBBaseError                = -7000,                        /* */
  55.                                                                 /* USB Services Errors */
  56.     kUSBInternalErr                = -6999,                        /* Internal error */
  57.     kUSBUnknownDeviceErr        = -6998,                        /*  device ref not recognised */
  58.     kUSBUnknownPipeErr            = -6997,                        /*  Pipe ref not recognised */
  59.     kUSBTooManyPipesErr            = -6996,                        /*  Too many pipes */
  60.     kUSBIncorrectTypeErr        = -6995,                        /*  Incorrect type */
  61.     kUSBRqErr                    = -6994,                        /*  Request error */
  62.     kUSBUnknownRequestErr        = -6993,                        /*  Unknown request */
  63.     kUSBTooManyTransactionsErr    = -6992,                        /*  Too many transactions */
  64.     kUSBAlreadyOpenErr            = -6991,                        /*  Already open */
  65.     kUSBNoDeviceErr                = -6990,                        /*  No device */
  66.     kUSBDeviceErr                = -6989,                        /*  Device error */
  67.     kUSBOutOfMemoryErr            = -6988,                        /*  Out of memory */
  68.     kUSBNotFound                = -6987,                        /*  Not found */
  69.     kUSBPBVersionError            = -6986,                        /*  Wrong pbVersion */
  70.     kUSBPBLengthError            = -6985,                        /*  pbLength too small */
  71.     kUSBCompletionError            = -6984,                        /*  no completion routine specified */
  72.     kUSBFlagsError                = -6983,                        /*  Unused flags not zeroed */
  73.     kUSBAbortedError            = -6982,                        /*  Pipe aborted */
  74.     kUSBNoBandwidthError        = -6981,                        /*  Not enough bandwidth available */
  75.     kUSBPipeIdleError            = -6980,                        /*  Pipe is Idle, it will not accept transactions */
  76.     kUSBPipeStalledError        = -6979,                        /*  Pipe has stalled, error needs to be cleared */
  77.     kUSBUnknownInterfaceErr        = -6978,                        /*  Interface ref not recognised */
  78.     kUSBDeviceBusy                = -6977,                        /*  Device is already being configured */
  79.     kUSBDevicePowerProblem        = -6976,                        /*  Device has a power problem */
  80.     kUSBInvalidBuffer            = -6975,                        /* bad buffer, usually nil */
  81.                                                                 /* */
  82.                                                                 /* USB Manager Errors */
  83.     kUSBBadDispatchTable        = -6950,                        /* Improper driver dispatch table */
  84.     kUSBUnknownNotification        = -6949,                        /* Notification type not defined */
  85.     kUSBQueueFull                = -6948,                        /* Internal queue maxxed */
  86.                                                                 /* */
  87.                                                                 /* Hardware Errors */
  88.                                                                 /* Note pipe stalls are communication */
  89.                                                                 /* errors. The affected pipe can not */
  90.                                                                 /* be used until USBClearPipeStallByReference  */
  91.                                                                 /* is used */
  92.                                                                 /* kUSBEndpointStallErr is returned in */
  93.                                                                 /* response to a stall handshake */
  94.                                                                 /* from a device. The device has to be */
  95.                                                                 /* cleared before a USBClearPipeStallByReference */
  96.                                                                 /* can be used */
  97.     kUSBLinkErr                    = -6916,
  98.     kUSBCRCErr                    = -6915,                        /*  Pipe stall, bad CRC */
  99.     kUSBBitstufErr                = -6914,                        /*  Pipe stall, bitstuffing */
  100.     kUSBDataToggleErr            = -6913,                        /*  Pipe stall, Bad data toggle */
  101.     kUSBEndpointStallErr        = -6912,                        /*  Device didn't understand */
  102.     kUSBNotRespondingErr        = -6911,                        /*  Pipe stall, No device, device hung */
  103.     kUSBPIDCheckErr                = -6910,                        /*  Pipe stall, PID CRC error */
  104.     kUSBWrongPIDErr                = -6909,                        /*  Pipe stall, Bad or wrong PID */
  105.     kUSBOverRunErr                = -6908,                        /*  Packet too large or more data than buffer */
  106.     kUSBUnderRunErr                = -6907,                        /*  Less data than buffer */
  107.     kUSBRes1Err                    = -6906,
  108.     kUSBRes2Err                    = -6905,
  109.     kUSBBufOvrRunErr            = -6904,                        /*  Host hardware failure on data in, PCI busy? */
  110.     kUSBBufUnderRunErr            = -6903,                        /*  Host hardware failure on data out, PCI busy? */
  111.     kUSBNotSent1Err                = -6902,                        /*  Transaction not sent */
  112.     kUSBNotSent2Err                = -6901                            /*  Transaction not sent */
  113. };
  114.  
  115. enum {
  116.                                                                 /* Flags */
  117.     kUSBTaskTimeFlag            = 1,
  118.     kUSBHubPower                = 2,
  119.     kUSBPowerReset                = 4,
  120.     kUSBHubReaddress            = 8,
  121.     kUSBAddressRequest            = 16
  122. };
  123.  
  124. enum {
  125.                                                                 /* Hub messages */
  126.     kUSBHubPortResetRequest        = 1
  127. };
  128.  
  129. /* ************* types ************* */
  130.  
  131. typedef SInt32                             USBReference;
  132. typedef USBReference                     USBDeviceRef;
  133. typedef USBReference                     USBInterfaceRef;
  134. typedef USBReference                     USBPipeRef;
  135. typedef USBReference                     USBBusRef;
  136. typedef UInt32                             USBPipeState;
  137. typedef UInt32                             USBCount;
  138. typedef UInt32                             USBFlags;
  139. typedef UInt8                             USBRequest;
  140. typedef UInt8                             USBDirection;
  141. typedef UInt8                             USBRqRecipient;
  142. typedef UInt8                             USBRqType;
  143. typedef UInt16                             USBRqIndex;
  144. typedef UInt16                             USBRqValue;
  145.  
  146.  
  147.  
  148. struct usbControlBits {
  149.     UInt8                             BMRequestType;
  150.     UInt8                             BRequest;
  151.     USBRqValue                         WValue;
  152.     USBRqIndex                         WIndex;
  153.     UInt16                             reserved4;
  154. };
  155. typedef struct usbControlBits            usbControlBits;
  156.  
  157. struct USBIsocFrame {
  158.     OSStatus                         frStatus;
  159.     UInt16                             frReqCount;
  160.     UInt16                             frActCount;
  161. };
  162. typedef struct USBIsocFrame                USBIsocFrame;
  163.  
  164. struct usbIsocBits {
  165.     USBIsocFrame *                    FrameList;
  166.     UInt32                             NumFrames;
  167. };
  168. typedef struct usbIsocBits                usbIsocBits;
  169.  
  170. struct usbHubBits {
  171.     UInt32                             Request;
  172.     UInt32                             Spare;
  173. };
  174. typedef struct usbHubBits                usbHubBits;
  175. typedef struct USBPB                     USBPB;
  176. typedef CALLBACK_API_C( void , USBCompletion )(USBPB *pb);
  177.  
  178. union USBVariantBits {
  179.     usbControlBits                     cntl;
  180.     usbIsocBits                     isoc;
  181.     usbHubBits                         hub;
  182. };
  183. typedef union USBVariantBits            USBVariantBits;
  184.  
  185. struct USBPB {
  186.  
  187.     void *                            qlink;
  188.     UInt16                             qType;
  189.     UInt16                             pbLength;
  190.     UInt16                             pbVersion;
  191.     UInt16                             reserved1;
  192.     UInt32                             reserved2;
  193.  
  194.     OSStatus                         usbStatus;
  195.     USBCompletion                     usbCompletion;
  196.     UInt32                             usbRefcon;
  197.  
  198.     USBReference                     usbReference;
  199.  
  200.     void *                            usbBuffer;
  201.     USBCount                         usbReqCount;
  202.     USBCount                         usbActCount;
  203.  
  204.     USBFlags                         usbFlags;
  205.  
  206.     USBVariantBits                     usb;
  207.  
  208.     UInt32                             usbFrame;
  209.  
  210.     UInt8                             usbClassType;
  211.     UInt8                             usbSubclass;
  212.     UInt8                             usbProtocol;
  213.     UInt8                             usbOther;
  214.  
  215.     UInt32                             reserved6;
  216.     UInt16                             reserved7;
  217.     UInt16                             reserved8;
  218.  
  219. };
  220.  
  221. #if !defined(OLDUSBNAMES)
  222. #define OLDUSBNAMES 0
  223. #endif
  224.  
  225. #if OLDUSBNAMES
  226. #define usbBMRequestType  usb.cntl.BMRequestType
  227. #define usbBRequest       usb.cntl.BRequest
  228. #define usbWValue         usb.cntl.WValue
  229. #define usbWIndex         usb.cntl.WIndex
  230. #endif
  231.  
  232. struct uslReq {
  233.     USBDirection                     usbDirection;
  234.     USBRqType                         usbType;
  235.     USBRqRecipient                     usbRecipient;
  236.     USBRequest                         usbRequest;
  237. };
  238. typedef struct uslReq                    uslReq;
  239.  
  240. enum {
  241.                                                                 /* BT 19Aug98, bump up to v1.10 for Isoc*/
  242.     kUSBCurrentPBVersion        = 0x0100,                        /* v1.00*/
  243.     kUSBIsocPBVersion            = 0x0109,                        /* v1.10*/
  244.     kUSBCurrentHubPB            = kUSBIsocPBVersion
  245. };
  246.  
  247.  
  248.  
  249.  
  250. #define kUSBNoCallBack ((USBCompletion)-1L)
  251.  
  252.  
  253. typedef UInt8                             bcdUSB;
  254. enum {
  255.     kUSBControl                    = 0,
  256.     kUSBIsoc                    = 1,
  257.     kUSBBulk                    = 2,
  258.     kUSBInterrupt                = 3,
  259.     kUSBAnyType                    = 0xFF
  260. };
  261.  
  262. /* endpoint type */
  263. enum {
  264.     kUSBOut                        = 0,
  265.     kUSBIn                        = 1,
  266.     kUSBNone                    = 2,
  267.     kUSBAnyDirn                    = 3
  268. };
  269.  
  270. /*USBDirection*/
  271. enum {
  272.     kUSBStandard                = 0,
  273.     kUSBClass                    = 1,
  274.     kUSBVendor                    = 2
  275. };
  276.  
  277. /*USBRqType*/
  278. enum {
  279.     kUSBDevice                    = 0,
  280.     kUSBInterface                = 1,
  281.     kUSBEndpoint                = 2,
  282.     kUSBOther                    = 3
  283. };
  284.  
  285. /*USBRqRecipient*/
  286. enum {
  287.     kUSBRqGetStatus                = 0,
  288.     kUSBRqClearFeature            = 1,
  289.     kUSBRqReserved1                = 2,
  290.     kUSBRqSetFeature            = 3,
  291.     kUSBRqReserved2                = 4,
  292.     kUSBRqSetAddress            = 5,
  293.     kUSBRqGetDescriptor            = 6,
  294.     kUSBRqSetDescriptor            = 7,
  295.     kUSBRqGetConfig                = 8,
  296.     kUSBRqSetConfig                = 9,
  297.     kUSBRqGetInterface            = 10,
  298.     kUSBRqSetInterface            = 11,
  299.     kUSBRqSyncFrame                = 12
  300. };
  301.  
  302. /*USBRequest*/
  303.  
  304. enum {
  305.     kUSBDeviceDesc                = 1,
  306.     kUSBConfDesc                = 2,
  307.     kUSBStringDesc                = 3,
  308.     kUSBInterfaceDesc            = 4,
  309.     kUSBEndpointDesc            = 5,
  310.     kUSBHIDDesc                    = 0x21,
  311.     kUSBReportDesc                = 0x22,
  312.     kUSBPhysicalDesc            = 0x23,
  313.     kUSBHUBDesc                    = 0x29
  314. };
  315.  
  316. /* descriptorType */
  317.  
  318. enum {
  319.     kUSBFeatureDeviceRemoteWakeup = 1,
  320.     kUSBFeatureEndpointStall    = 0
  321. };
  322.  
  323. /* Feature selectors */
  324. enum {
  325.     kUSBActive                    = 0,                            /* Pipe can accept new transactions*/
  326.     kUSBIdle                    = 1,                            /* Pipe will not accept new transactions*/
  327.     kUSBStalled                    = 2                                /* An error occured on the pipe*/
  328. };
  329.  
  330. enum {
  331.     kUSB100mAAvailable            = 50,
  332.     kUSB500mAAvailable            = 250,
  333.     kUSB100mA                    = 50,
  334.     kUSBAtrBusPowered            = 0x80,
  335.     kUSBAtrSelfPowered            = 0x40,
  336.     kUSBAtrRemoteWakeup            = 0x20
  337. };
  338.  
  339. enum {
  340.     kUSBRel10                    = 0x0100
  341. };
  342.  
  343. #define USB_CONSTANT16(x)    ((((x) >> 8) & 0x0ff) | ((x & 0xff) << 8))
  344. enum {
  345.     kUSBDeviceDescriptorLength    = 0x12,
  346.     kUSBInterfaceDescriptorLength = 0x09
  347. };
  348.  
  349.  
  350. struct USBDeviceDescriptor {
  351.     UInt8                             length;
  352.     UInt8                             descType;
  353.     UInt16                             usbRel;
  354.     UInt8                             deviceClass;
  355.     UInt8                             deviceSubClass;
  356.     UInt8                             protocol;
  357.     UInt8                             maxPacketSize;
  358.     UInt16                             vendor;
  359.     UInt16                             product;
  360.     UInt16                             devRel;
  361.     UInt8                             manuIdx;
  362.     UInt8                             prodIdx;
  363.     UInt8                             serialIdx;
  364.     UInt8                             numConf;
  365.     UInt16                             descEnd;                    /* was "end", but this is reserved in some languages*/
  366. };
  367. typedef struct USBDeviceDescriptor        USBDeviceDescriptor;
  368. #ifndef OLDCLASSNAMES
  369. #ifndef __cplusplus
  370. #define class deviceClass
  371. #define subClass deviceSubClass
  372. #endif
  373. #endif
  374. typedef USBDeviceDescriptor *            USBDeviceDescriptorPtr;
  375.  
  376. struct USBDescriptorHeader {
  377.     UInt8                             length;
  378.     UInt8                             descriptorType;
  379. };
  380. typedef struct USBDescriptorHeader        USBDescriptorHeader;
  381. typedef USBDescriptorHeader *            USBDescriptorHeaderPtr;
  382.  
  383. struct USBConfigurationDescriptor {
  384.     UInt8                             length;
  385.     UInt8                             descriptorType;
  386.     UInt16                             totalLength;
  387.     UInt8                             numInterfaces;
  388.     UInt8                             configValue;
  389.     UInt8                             configStrIndex;
  390.     UInt8                             attributes;
  391.     UInt8                             maxPower;
  392. };
  393. typedef struct USBConfigurationDescriptor USBConfigurationDescriptor;
  394. typedef USBConfigurationDescriptor *    USBConfigurationDescriptorPtr;
  395.  
  396. struct USBInterfaceDescriptor {
  397.     UInt8                             length;
  398.     UInt8                             descriptorType;
  399.     UInt8                             interfaceNumber;
  400.     UInt8                             alternateSetting;
  401.     UInt8                             numEndpoints;
  402.     UInt8                             interfaceClass;
  403.     UInt8                             interfaceSubClass;
  404.     UInt8                             interfaceProtocol;
  405.     UInt8                             interfaceStrIndex;
  406. };
  407. typedef struct USBInterfaceDescriptor    USBInterfaceDescriptor;
  408. typedef USBInterfaceDescriptor *        USBInterfaceDescriptorPtr;
  409.  
  410. struct USBEndPointDescriptor {
  411.     UInt8                             length;
  412.     UInt8                             descriptorType;
  413.     UInt8                             endpointAddress;
  414.     UInt8                             attributes;
  415.     UInt16                             maxPacketSize;
  416.     UInt8                             interval;
  417. };
  418. typedef struct USBEndPointDescriptor    USBEndPointDescriptor;
  419. typedef USBEndPointDescriptor *            USBEndPointDescriptorPtr;
  420.  
  421. struct USBHIDDescriptor {
  422.     UInt8                             descLen;
  423.     UInt8                             descType;
  424.     UInt16                             descVersNum;
  425.     UInt8                             hidCountryCode;
  426.     UInt8                             hidNumDescriptors;
  427.     UInt8                             hidDescriptorType;
  428.     UInt8                             hidDescriptorLengthLo;        /* can't make this a single 16bit value or the compiler will add a filler byte*/
  429.     UInt8                             hidDescriptorLengthHi;
  430. };
  431. typedef struct USBHIDDescriptor            USBHIDDescriptor;
  432. typedef USBHIDDescriptor *                USBHIDDescriptorPtr;
  433.  
  434. struct USBHIDReportDesc {
  435.     UInt8                             hidDescriptorType;
  436.     UInt8                             hidDescriptorLengthLo;        /* can't make this a single 16bit value or the compiler will add a filler byte*/
  437.     UInt8                             hidDescriptorLengthHi;
  438. };
  439. typedef struct USBHIDReportDesc            USBHIDReportDesc;
  440. typedef USBHIDReportDesc *                USBHIDReportDescPtr;
  441.  
  442. struct USBHubPortStatus {
  443.     UInt16                             portFlags;                    /* Port status flags */
  444.     UInt16                             portChangeFlags;            /* Port changed flags */
  445. };
  446. typedef struct USBHubPortStatus            USBHubPortStatus;
  447. typedef USBHubPortStatus *                USBHubPortStatusPtr;
  448. /* ********* ProtoTypes *************** */
  449. /* For dealing with endianisms */
  450. EXTERN_API_C( UInt16 )
  451. HostToUSBWord                    (UInt16                 value);
  452.  
  453. EXTERN_API_C( UInt16 )
  454. USBToHostWord                    (UInt16                 value);
  455.  
  456. EXTERN_API_C( UInt32 )
  457. HostToUSBLong                    (UInt32                 value);
  458.  
  459. EXTERN_API_C( UInt32 )
  460. USBToHostLong                    (UInt32                 value);
  461.  
  462. /* Main prototypes */
  463. /* Transfer commands */
  464. EXTERN_API_C( OSStatus )
  465. USBDeviceRequest                (USBPB *                pb);
  466.  
  467. EXTERN_API_C( OSStatus )
  468. USBOpenPipe                        (USBPB *                pb);
  469.  
  470. EXTERN_API_C( OSStatus )
  471. USBBulkWrite                    (USBPB *                pb);
  472.  
  473. EXTERN_API_C( OSStatus )
  474. USBBulkRead                        (USBPB *                pb);
  475.  
  476. EXTERN_API_C( OSStatus )
  477. USBIntRead                        (USBPB *                pb);
  478.  
  479. EXTERN_API_C( OSStatus )
  480. USBIntWrite                        (USBPB *                pb);
  481.  
  482. EXTERN_API_C( OSStatus )
  483. USBIsocRead                        (USBPB *                pb);
  484.  
  485. EXTERN_API_C( OSStatus )
  486. USBIsocWrite                    (USBPB *                pb);
  487.  
  488. /* Pipe state control */
  489. EXTERN_API_C( OSStatus )
  490. USBClearPipeStallByReference    (USBPipeRef             ref);
  491.  
  492. EXTERN_API_C( OSStatus )
  493. USBAbortPipeByReference            (USBReference             ref);
  494.  
  495. EXTERN_API_C( OSStatus )
  496. USBResetPipeByReference            (USBReference             ref);
  497.  
  498. EXTERN_API_C( OSStatus )
  499. USBSetPipeIdleByReference        (USBPipeRef             ref);
  500.  
  501. EXTERN_API_C( OSStatus )
  502. USBSetPipeActiveByReference        (USBPipeRef             ref);
  503.  
  504. EXTERN_API_C( OSStatus )
  505. USBClosePipeByReference            (USBPipeRef             ref);
  506.  
  507. EXTERN_API_C( OSStatus )
  508. USBGetPipeStatusByReference        (USBReference             ref,
  509.                                  USBPipeState *            state);
  510.  
  511.  
  512. /* Configuration services */
  513. EXTERN_API_C( OSStatus )
  514. USBFindNextInterface            (USBPB *                pb);
  515.  
  516. EXTERN_API_C( OSStatus )
  517. USBOpenDevice                    (USBPB *                pb);
  518.  
  519. EXTERN_API_C( OSStatus )
  520. USBSetConfiguration                (USBPB *                pb);
  521.  
  522. EXTERN_API_C( OSStatus )
  523. USBNewInterfaceRef                (USBPB *                pb);
  524.  
  525. EXTERN_API_C( OSStatus )
  526. USBDisposeInterfaceRef            (USBPB *                pb);
  527.  
  528. EXTERN_API_C( OSStatus )
  529. USBConfigureInterface            (USBPB *                pb);
  530.  
  531. EXTERN_API_C( OSStatus )
  532. USBFindNextPipe                    (USBPB *                pb);
  533.  
  534.  
  535. /* Dealing with descriptors. */
  536. /* Note most of this is temprorary */
  537. EXTERN_API_C( OSStatus )
  538. USBGetConfigurationDescriptor    (USBPB *                pb);
  539.  
  540. EXTERN_API_C( OSStatus )
  541. USBGetFullConfigurationDescriptor (USBPB *                pb);
  542.  
  543. EXTERN_API_C( OSStatus )
  544. USBFindNextEndpointDescriptorImmediate (USBPB *            pb);
  545.  
  546. EXTERN_API_C( OSStatus )
  547. USBFindNextInterfaceDescriptorImmediate (USBPB *        pb);
  548.  
  549. EXTERN_API_C( OSStatus )
  550. USBFindNextAssociatedDescriptor    (USBPB *                pb);
  551.  
  552.  
  553.  
  554. /* Utility functions */
  555. EXTERN_API_C( OSStatus )
  556. USBResetDevice                    (USBPB *                pb);
  557.  
  558. EXTERN_API_C( OSStatus )
  559. USBGetFrameNumberImmediate        (USBPB *                pb);
  560.  
  561. EXTERN_API_C( OSStatus )
  562. USBDelay                        (USBPB *                pb);
  563.  
  564. EXTERN_API_C( OSStatus )
  565. USBAllocMem                        (USBPB *                pb);
  566.  
  567. EXTERN_API_C( OSStatus )
  568. USBDeallocMem                    (USBPB *                pb);
  569.  
  570. /* Expert interface functions */
  571. EXTERN_API_C( OSStatus )
  572. USBExpertInstallInterfaceDriver    (USBDeviceRef             ref,
  573.                                  USBDeviceDescriptorPtr  desc,
  574.                                  USBInterfaceDescriptorPtr  interfacePtr,
  575.                                  USBReference             hubRef,
  576.                                  UInt32                 busPowerAvailable);
  577.  
  578. EXTERN_API_C( OSStatus )
  579. USBExpertRemoveInterfaceDriver    (USBDeviceRef             ref);
  580.  
  581. EXTERN_API_C( OSStatus )
  582. USBExpertInstallDeviceDriver    (USBDeviceRef             ref,
  583.                                  USBDeviceDescriptorPtr  desc,
  584.                                  USBReference             hubRef,
  585.                                  UInt32                 port,
  586.                                  UInt32                 busPowerAvailable);
  587.  
  588. EXTERN_API_C( OSStatus )
  589. USBExpertRemoveDeviceDriver        (USBDeviceRef             ref);
  590.  
  591. EXTERN_API_C( OSStatus )
  592. USBExpertStatus                    (USBDeviceRef             ref,
  593.                                  void *                    pointer,
  594.                                  UInt32                 value);
  595.  
  596. EXTERN_API_C( OSStatus )
  597. USBExpertFatalError                (USBDeviceRef             ref,
  598.                                  OSStatus                 status,
  599.                                  void *                    pointer,
  600.                                  UInt32                 value);
  601.  
  602. EXTERN_API_C( OSStatus )
  603. USBExpertNotify                    (void *                    note);
  604.  
  605. EXTERN_API_C( OSStatus )
  606. USBExpertStatusLevel            (UInt32                 level,
  607.                                  USBDeviceRef             ref,
  608.                                  char *                    status,
  609.                                  UInt32                 value);
  610.  
  611. EXTERN_API_C( OSStatus )
  612. USBExpertSetDevicePowerStatus    (USBDeviceRef             ref,
  613.                                  UInt32                 reserved1,
  614.                                  UInt32                 reserved2,
  615.                                  UInt32                 powerStatus,
  616.                                  UInt32                 busPowerAvailable,
  617.                                  UInt32                 busPowerNeeded);
  618.  
  619. enum {
  620.     kUSBDevicePower_PowerOK        = 0,
  621.     kUSBDevicePower_BusPowerInsufficient = 1,
  622.     kUSBDevicePower_BusPowerNotAllFeatures = 2,
  623.     kUSBDevicePower_SelfPowerInsufficient = 3,
  624.     kUSBDevicePower_SelfPowerNotAllFeatures = 4,
  625.     kUSBDevicePower_HubPortOk    = 5,
  626.     kUSBDevicePower_HubPortOverCurrent = 6,
  627.     kUSBDevicePower_BusPoweredHubOnLowPowerPort = 7,
  628.     kUSBDevicePower_BusPoweredHubToBusPoweredHub = 8,
  629.     kUSBDevicePower_Reserved3    = 9,
  630.     kUSBDevicePower_Reserved4    = 10
  631. };
  632.  
  633.  
  634. /* For hubs only */
  635. EXTERN_API_C( OSStatus )
  636. USBHubAddDevice                    (USBPB *                pb);
  637.  
  638. EXTERN_API_C( OSStatus )
  639. USBHubConfigurePipeZero            (USBPB *                pb);
  640.  
  641. EXTERN_API_C( OSStatus )
  642. USBHubSetAddress                (USBPB *                pb);
  643.  
  644. EXTERN_API_C( OSStatus )
  645. USBHubDeviceRemoved                (USBPB *                pb);
  646.  
  647.  
  648. EXTERN_API_C( UInt8 )
  649. USBMakeBMRequestType            (UInt8                     direction,
  650.                                  UInt8                     reqtype,
  651.                                  UInt8                     recipient);
  652.  
  653. EXTERN_API_C( OSStatus )
  654. USBControlRequest                (USBPB *                pb);
  655.  
  656.  
  657. typedef UInt32                             USBLocationID;
  658. enum {
  659.     kUSBLocationNibbleFormat    = 0                                /* Other values are reserved for future types (like when we have more than 16 ports per hub)*/
  660. };
  661.  
  662.  
  663. enum {
  664.     kNoDeviceRef                = -1
  665. };
  666.  
  667. /* Status Level constants*/
  668. /*
  669. Level 1: Fatal errors
  670. Level 2: General errors that may or may not effect operation
  671. Level 3: General driver messages.  The "AddStatus" call that drivers use comes through as a level 3.  This is also the default level at boot time.
  672. Level 4: Important status messages from the Expert and USL.
  673. Level 5: General status messages from the Expert and USL.
  674. */
  675. enum {
  676.     kUSBStatusLevelFatal        = 1,
  677.     kUSBStatusLevelError        = 2,
  678.     kUSBStatusLevelClient        = 3,
  679.     kUSBStatusLevelGeneral        = 4,
  680.     kUSBStatusLevelVerbose        = 5
  681. };
  682.  
  683. /* Expert Notification Types*/
  684. typedef UInt8                             USBNotificationType;
  685. typedef UInt8                             USBDriverMessage;
  686. enum {
  687.     kNotifyAddDevice            = 0x00,
  688.     kNotifyRemoveDevice            = 0x01,
  689.     kNotifyAddInterface            = 0x02,
  690.     kNotifyRemoveInterface        = 0x03,
  691.     kNotifyGetDeviceDescriptor    = 0x04,
  692.     kNotifyGetInterfaceDescriptor = 0x05,
  693.     kNotifyGetNextDeviceByClass    = 0x06,
  694.     kNotifyGetDriverConnectionID = 0x07,
  695.     kNotifyInstallDeviceNotification = 0x08,
  696.     kNotifyRemoveDeviceNotification = 0x09,
  697.     kNotifyDeviceRefToBusRef    = 0x0A,
  698.     kNotifyDriverNotify            = 0x0C,
  699.     kNotifyParentNotify            = 0x0D,
  700.     kNotifyAnyEvent                = 0xFF,
  701.     kNotifyPowerState            = 0x17,
  702.     kNotifyStatus                = 0x18,
  703.     kNotifyFatalError            = 0x19
  704. };
  705.  
  706. /*
  707.    USB Manager wildcard constants for USBGetNextDeviceByClass
  708.    and USBInstallDeviceNotification.
  709. */
  710. typedef UInt16                             USBManagerWildcard;
  711. enum {
  712.     kUSBAnyClass                = 0xFFFF,
  713.     kUSBAnySubClass                = 0xFFFF,
  714.     kUSBAnyProtocol                = 0xFFFF,
  715.     kUSBAnyVendor                = 0xFFFF,
  716.     kUSBAnyProduct                = 0xFFFF
  717. };
  718.  
  719.  
  720.  
  721.  
  722. struct ExpertNotificationData {
  723.     USBNotificationType             notification;
  724.     UInt8                             filler[1];                    /* unused due to 2-byte 68k alignment*/
  725.     USBDeviceRef *                    deviceRef;
  726.     UInt32                             busPowerAvailable;
  727.     void *                            data;
  728.     UInt32                             info1;
  729.     UInt32                             info2;
  730. };
  731. typedef struct ExpertNotificationData    ExpertNotificationData;
  732. typedef ExpertNotificationData *        ExpertNotificationDataPtr;
  733. /* Definition of function pointer passed in ExpertEntryProc*/
  734. typedef CALLBACK_API_C( OSStatus , ExpertNotificationProcPtr )(ExpertNotificationDataPtr pNotificationData);
  735. /* Definition of expert's callback installation function*/
  736. typedef CALLBACK_API_C( OSStatus , ExpertEntryProcPtr )(ExpertNotificationProcPtr pExpertNotify);
  737. /* Device Notification Callback Routine*/
  738. typedef CALLBACK_API_C( void , USBDeviceNotificationCallbackProcPtr )(void *pb);
  739. /* Device Notification Parameter Block*/
  740.  
  741. struct USBDeviceNotificationParameterBlock {
  742.     UInt16                             pbLength;
  743.     UInt16                             pbVersion;
  744.     USBNotificationType             usbDeviceNotification;
  745.     UInt8                             reserved1[1];                /* needed because of 2-byte 68k alignment*/
  746.     USBDeviceRef                     usbDeviceRef;
  747.     UInt16                             usbClass;
  748.     UInt16                             usbSubClass;
  749.     UInt16                             usbProtocol;
  750.     UInt16                             usbVendor;
  751.     UInt16                             usbProduct;
  752.     OSStatus                         result;
  753.     UInt32                             token;
  754.     USBDeviceNotificationCallbackProcPtr  callback;
  755.     UInt32                             refcon;
  756. };
  757. typedef struct USBDeviceNotificationParameterBlock USBDeviceNotificationParameterBlock;
  758. typedef USBDeviceNotificationParameterBlock * USBDeviceNotificationParameterBlockPtr;
  759. /* Definition of USBDriverNotificationCallback Routine*/
  760. typedef CALLBACK_API_C( void , USBDriverNotificationCallbackPtr )(OSStatus status, UInt32 refcon);
  761. /* Public Functions*/
  762. EXTERN_API_C( OSStatus )
  763. USBGetNextDeviceByClass            (USBDeviceRef *            deviceRef,
  764.                                  CFragConnectionID *    connID,
  765.                                  UInt16                 theClass,
  766.                                  UInt16                 theSubClass,
  767.                                  UInt16                 theProtocol);
  768.  
  769. EXTERN_API_C( OSStatus )
  770. USBGetDeviceDescriptor            (USBDeviceRef *            deviceRef,
  771.                                  USBDeviceDescriptor *    deviceDescriptor,
  772.                                  UInt32                 size);
  773.  
  774. EXTERN_API_C( OSStatus )
  775. USBGetInterfaceDescriptor        (USBInterfaceRef *        interfaceRef,
  776.                                  USBInterfaceDescriptor * interfaceDescriptor,
  777.                                  UInt32                 size);
  778.  
  779. EXTERN_API_C( OSStatus )
  780. USBGetDriverConnectionID        (USBDeviceRef *            deviceRef,
  781.                                  CFragConnectionID *    connID);
  782.  
  783. EXTERN_API_C( void )
  784. USBInstallDeviceNotification    (USBDeviceNotificationParameterBlock * pb);
  785.  
  786. EXTERN_API_C( OSStatus )
  787. USBRemoveDeviceNotification        (UInt32                 token);
  788.  
  789. EXTERN_API_C( OSStatus )
  790. USBDeviceRefToBusRef            (USBDeviceRef *            deviceRef,
  791.                                  USBBusRef *            busRef);
  792.  
  793. EXTERN_API_C( OSStatus )
  794. USBDriverNotify                    (USBReference             reference,
  795.                                  USBDriverMessage         mesg,
  796.                                  UInt32                 refcon,
  797.                                  USBDriverNotificationCallbackPtr  callback);
  798.  
  799. EXTERN_API_C( OSStatus )
  800. USBExpertNotifyParent            (USBReference             reference,
  801.                                  void *                    pointer);
  802.  
  803. typedef CALLBACK_API_C( void , HIDInterruptProcPtr )(UInt32 refcon, void *theData);
  804. /* HID Install Interrupt prototype*/
  805. typedef CALLBACK_API_C( OSStatus , USBHIDInstallInterruptProcPtr )(HIDInterruptProcPtr pInterruptProc, UInt32 refcon);
  806. /* HID Poll Device prototype*/
  807. typedef CALLBACK_API_C( OSStatus , USBHIDPollDeviceProcPtr )(void );
  808. /* HID Control Device prototype*/
  809. typedef CALLBACK_API_C( OSStatus , USBHIDControlDeviceProcPtr )(UInt32 theControlSelector, void *theControlData);
  810. /* HID Get Device Info prototype*/
  811. typedef CALLBACK_API_C( OSStatus , USBHIDGetDeviceInfoProcPtr )(UInt32 theInfoSelector, void *theInfo);
  812. /* HID Enter Polled Mode prototype*/
  813. typedef CALLBACK_API_C( OSStatus , USBHIDEnterPolledModeProcPtr )(void );
  814. /* HID Exit Polled Mode prototype*/
  815. typedef CALLBACK_API_C( OSStatus , USBHIDExitPolledModeProcPtr )(void );
  816.  
  817. struct USBHIDModuleDispatchTable {
  818.     UInt32                             hidDispatchVersion;
  819.     USBHIDInstallInterruptProcPtr     pUSBHIDInstallInterrupt;
  820.     USBHIDPollDeviceProcPtr         pUSBHIDPollDevice;
  821.     USBHIDControlDeviceProcPtr         pUSBHIDControlDevice;
  822.     USBHIDGetDeviceInfoProcPtr         pUSBHIDGetDeviceInfo;
  823.     USBHIDEnterPolledModeProcPtr     pUSBHIDEnterPolledMode;
  824.     USBHIDExitPolledModeProcPtr     pUSBHIDExitPolledMode;
  825. };
  826. typedef struct USBHIDModuleDispatchTable USBHIDModuleDispatchTable;
  827. typedef USBHIDModuleDispatchTable *        USBHIDModuleDispatchTablePtr;
  828. /*    Prototypes Tue, Mar 17, 1998 4:54:30 PM    */
  829. EXTERN_API_C( OSStatus )
  830. USBHIDInstallInterrupt            (HIDInterruptProcPtr     HIDInterruptFunction,
  831.                                  UInt32                 refcon);
  832.  
  833. EXTERN_API_C( OSStatus )
  834. USBHIDPollDevice                (void);
  835.  
  836. EXTERN_API_C( OSStatus )
  837. USBHIDControlDevice                (UInt32                 theControlSelector,
  838.                                  void *                    theControlData);
  839.  
  840. EXTERN_API_C( OSStatus )
  841. USBHIDGetDeviceInfo                (UInt32                 theInfoSelector,
  842.                                  void *                    theInfo);
  843.  
  844. EXTERN_API_C( OSStatus )
  845. USBHIDEnterPolledMode            (void);
  846.  
  847. EXTERN_API_C( OSStatus )
  848. USBHIDExitPolledMode            (void);
  849.  
  850. EXTERN_API_C( void )
  851. HIDNotification                    (UInt32                 devicetype,
  852.                                  UInt8                     NewHIDData[],
  853.                                  UInt8                     OldHIDData[]);
  854.  
  855. enum {
  856.     kHIDRqGetReport                = 1,
  857.     kHIDRqGetIdle                = 2,
  858.     kHIDRqGetProtocol            = 3,
  859.     kHIDRqSetReport                = 9,
  860.     kHIDRqSetIdle                = 10,
  861.     kHIDRqSetProtocol            = 11
  862. };
  863.  
  864. enum {
  865.     kHIDRtInputReport            = 1,
  866.     kHIDRtOutputReport            = 2,
  867.     kHIDRtFeatureReport            = 3
  868. };
  869.  
  870. enum {
  871.     kHIDBootProtocolValue        = 0,
  872.     kHIDReportProtocolValue        = 1
  873. };
  874.  
  875. enum {
  876.     kHIDKeyboardInterfaceProtocol = 1,
  877.     kHIDMouseInterfaceProtocol    = 2
  878. };
  879.  
  880. enum {
  881.     kHIDSetLEDStateByBits        = 1,
  882.     kHIDSetLEDStateByBitMask    = 1,
  883.     kHIDSetLEDStateByIDNumber    = 2,
  884.     kHIDRemoveInterruptHandler    = 3,
  885.     kHIDEnableDemoMode            = 4,
  886.     kHIDDisableDemoMode            = 5
  887. };
  888.  
  889. enum {
  890.     kHIDGetLEDStateByBits        = 1,                            /* not supported in 1.0 of keyboard module*/
  891.     kHIDGetLEDStateByBitMask    = 1,                            /* not supported in 1.0 of keyboard module*/
  892.     kHIDGetLEDStateByIDNumber    = 2,
  893.     kHIDGetDeviceCountryCode    = 3,                            /* not supported in 1.0 HID modules*/
  894.     kHIDGetDeviceUnitsPerInch    = 4,                            /* only supported in mouse HID module*/
  895.     kHIDGetInterruptHandler        = 5,
  896.     kHIDGetCurrentKeys            = 6,                            /* only supported in keyboard HID module*/
  897.     kHIDGetInterruptRefcon        = 7,
  898.     kHIDGetVendorID                = 8,
  899.     kHIDGetProductID            = 9
  900. };
  901.  
  902.  
  903. enum {
  904.     kNumLockLED                    = 0,
  905.     kCapsLockLED                = 1,
  906.     kScrollLockLED                = 2,
  907.     kComposeLED                    = 3,
  908.     kKanaLED                    = 4
  909. };
  910.  
  911. enum {
  912.     kNumLockLEDMask                = 1 << kNumLockLED,
  913.     kCapsLockLEDMask            = 1 << kCapsLockLED,
  914.     kScrollLockLEDMask            = 1 << kScrollLockLED,
  915.     kComposeLEDMask                = 1 << kComposeLED,
  916.     kKanaLEDMask                = 1 << kKanaLED
  917. };
  918.  
  919. enum {
  920.     kUSBCapsLockKey                = 0x39,
  921.     kUSBNumLockKey                = 0x53,
  922.     kUSBScrollLockKey            = 0x47
  923. };
  924.  
  925.  
  926. struct USBMouseData {
  927.     UInt16                             buttons;
  928.     SInt16                             XDelta;
  929.     SInt16                             YDelta;
  930. };
  931. typedef struct USBMouseData                USBMouseData;
  932. typedef USBMouseData *                    USBMouseDataPtr;
  933.  
  934. struct USBKeyboardData {
  935.     UInt16                             keycount;
  936.     UInt16                             usbkeycode[32];
  937. };
  938. typedef struct USBKeyboardData            USBKeyboardData;
  939. typedef USBKeyboardData *                USBKeyboardDataPtr;
  940.  
  941. union USBHIDData {
  942.     USBKeyboardData                 kbd;
  943.     USBMouseData                     mouse;
  944. };
  945. typedef union USBHIDData                USBHIDData;
  946. typedef USBHIDData *                    USBHIDDataPtr;
  947. EXTERN_API_C( void )
  948. StartCompoundClassDriver        (USBDeviceRef             device,
  949.                                  UInt16                 classID,
  950.                                  UInt16                 subClass);
  951.  
  952. enum {
  953.     kUSBCompositeClass            = 0,
  954.     kUSBAudioClass                = 1,
  955.     kUSBCommClass                = 2,
  956.     kUSBHIDClass                = 3,
  957.     kUSBDisplayClass            = 4,
  958.     kUSBPrintingClass            = 7,
  959.     kUSBMassStorageClass        = 8,
  960.     kUSBHubClass                = 9,
  961.     kUSBDataClass                = 10,
  962.     kUSBVendorSpecificClass        = 0xFF
  963. };
  964.  
  965. enum {
  966.     kUSBCompositeSubClass        = 0,
  967.     kUSBHubSubClass                = 1,
  968.     kUSBPrinterSubclass            = 1
  969. };
  970.  
  971. enum {
  972.     kUSBHIDInterfaceClass        = 0x03
  973. };
  974.  
  975. enum {
  976.     kUSBNoInterfaceSubClass        = 0x00,
  977.     kUSBBootInterfaceSubClass    = 0x01
  978. };
  979.  
  980. enum {
  981.     kUSBNoInterfaceProtocol        = 0x00,
  982.     kUSBKeyboardInterfaceProtocol = 0x01,
  983.     kUSBMouseInterfaceProtocol    = 0x02
  984. };
  985.  
  986. enum {
  987.     kUSBPrinterUnidirectionalProtocol = 0x01,
  988.     kUSBPrinterBidirectionalProtocol = 0x02
  989. };
  990.  
  991.  
  992. enum {
  993.     kServiceCategoryUSB            = FOUR_CHAR_CODE('usb ')        /* USB*/
  994. };
  995.  
  996. /* SOMETHING NEEDS TO BE DONE WITH THIS - */
  997. enum {
  998.     kUSBTypeIsHub                = FOUR_CHAR_CODE('hubd'),        /* Hub*/
  999.     kUSBTypeIsHID                = FOUR_CHAR_CODE('HIDd'),        /* Human Interface Device*/
  1000.     kUSBTypeIsDisplay            = FOUR_CHAR_CODE('disp'),        /* Display */
  1001.     kUSBTypeIsModem                = FOUR_CHAR_CODE('modm')        /* Modem*/
  1002. };
  1003.  
  1004. enum {
  1005.     kUSBDriverFileType            = FOUR_CHAR_CODE('ndrv'),
  1006.     kUSBDriverRsrcType            = FOUR_CHAR_CODE('usbd'),
  1007.     kUSBShimRsrcType            = FOUR_CHAR_CODE('usbs')
  1008. };
  1009.  
  1010. enum {
  1011.     kTheUSBDriverDescriptionSignature = FOUR_CHAR_CODE('usbd')
  1012. };
  1013.  
  1014. enum {
  1015.     kInitialUSBDriverDescriptor    = 0
  1016. };
  1017.  
  1018.  
  1019.  
  1020. typedef UInt32                             USBDriverDescVersion;
  1021. /*  Driver Loading Options*/
  1022. typedef UInt32                             USBDriverLoadingOptions;
  1023. enum {
  1024.     kUSBDoNotMatchGenericDevice    = 0x00000001,                    /* Driver's VendorID must match Device's VendorID*/
  1025.     kUSBDoNotMatchInterface        = 0x00000002,                    /* Do not load this driver as an interface driver.*/
  1026.     kUSBProtocolMustMatch        = 0x00000004,                    /* Do not load this driver if protocol field doesn't match.*/
  1027.     kUSBInterfaceMatchOnly        = 0x00000008                    /* Only load this driver as an interface driver.*/
  1028. };
  1029.  
  1030. enum {
  1031.     kClassDriverPluginVersion    = 0x00001100
  1032. };
  1033.  
  1034.  
  1035.  
  1036.  
  1037. struct USBDeviceInfo {
  1038.     UInt16                             usbVendorID;                /* USB Vendor ID*/
  1039.     UInt16                             usbProductID;                /* USB Product ID.*/
  1040.     UInt16                             usbDeviceReleaseNumber;        /* Release Number of Device*/
  1041.     UInt16                             usbDeviceProtocol;            /* Protocol Info.*/
  1042. };
  1043. typedef struct USBDeviceInfo            USBDeviceInfo;
  1044. typedef USBDeviceInfo *                    USBDeviceInfoPtr;
  1045.  
  1046. struct USBInterfaceInfo {
  1047.     UInt8                             usbConfigValue;                /* Configuration Value*/
  1048.     UInt8                             usbInterfaceNum;            /* Interface Number*/
  1049.     UInt8                             usbInterfaceClass;            /* Interface Class*/
  1050.     UInt8                             usbInterfaceSubClass;        /* Interface SubClass*/
  1051.     UInt8                             usbInterfaceProtocol;        /* Interface Protocol*/
  1052. };
  1053. typedef struct USBInterfaceInfo            USBInterfaceInfo;
  1054. typedef USBInterfaceInfo *                USBInterfaceInfoPtr;
  1055.  
  1056. struct USBDriverType {
  1057.     Str31                             nameInfoStr;                /* Driver's name when loading into the Name Registry.*/
  1058.     UInt8                             usbDriverClass;                /* USB Class this driver belongs to.*/
  1059.     UInt8                             usbDriverSubClass;            /* Module type*/
  1060.     NumVersion                         usbDriverVersion;            /* Class driver version number.*/
  1061. };
  1062. typedef struct USBDriverType            USBDriverType;
  1063. typedef USBDriverType *                    USBDriverTypePtr;
  1064.  
  1065. struct USBDriverDescription {
  1066.     OSType                             usbDriverDescSignature;        /* Signature field of this structure.*/
  1067.     USBDriverDescVersion             usbDriverDescVersion;        /* Version of this data structure.*/
  1068.     USBDeviceInfo                     usbDeviceInfo;                /* Product & Vendor Info*/
  1069.     USBInterfaceInfo                 usbInterfaceInfo;            /* Interface info*/
  1070.     USBDriverType                     usbDriverType;                /* Driver Info.*/
  1071.     USBDriverLoadingOptions         usbDriverLoadingOptions;    /* Options for class driver loading.*/
  1072. };
  1073. typedef struct USBDriverDescription        USBDriverDescription;
  1074. typedef USBDriverDescription *            USBDriverDescriptionPtr;
  1075. /*
  1076.    Dispatch Table
  1077.    Definition of class driver's HW Validation proc.
  1078. */
  1079. typedef CALLBACK_API_C( OSStatus , USBDValidateHWProcPtr )(USBDeviceRef device, USBDeviceDescriptorPtr pDesc);
  1080. /*
  1081.    Definition of class driver's device initialization proc.
  1082.    Called if the driver is being loaded for a device
  1083. */
  1084. typedef CALLBACK_API_C( OSStatus , USBDInitializeDeviceProcPtr )(USBDeviceRef device, USBDeviceDescriptorPtr pDesc, UInt32 busPowerAvailable);
  1085. /* Definition of class driver's interface initialization proc.*/
  1086. typedef CALLBACK_API_C( OSStatus , USBDInitializeInterfaceProcPtr )(UInt32 interfaceNum, USBInterfaceDescriptorPtr pInterface, USBDeviceDescriptorPtr pDevice, USBInterfaceRef interfaceRef);
  1087. /* Definition of class driver's finalization proc.*/
  1088. typedef CALLBACK_API_C( OSStatus , USBDFinalizeProcPtr )(USBDeviceRef device, USBDeviceDescriptorPtr pDesc);
  1089.  
  1090. typedef UInt32                             USBDriverNotification;
  1091. enum {
  1092.     kNotifySystemSleepRequest    = 0x00000001,
  1093.     kNotifySystemSleepDemand    = 0x00000002,
  1094.     kNotifyHubEnumQuery            = 0x00000006,
  1095.     kNotifyChildMessage            = 0x00000007,
  1096.     kNotifyDriverBeingRemoved    = 0x0000000B
  1097. };
  1098.  
  1099. /*
  1100.    Definition of driver's notificatipn proc.      
  1101.    Added refcon for 1.1 version of dispatch table
  1102. */
  1103. typedef CALLBACK_API_C( OSStatus , USBDDriverNotifyProcPtr )(USBDriverNotification notification, void *pointer, UInt32 refcon);
  1104.  
  1105. struct USBClassDriverPluginDispatchTable {
  1106.     UInt32                             pluginVersion;
  1107.     USBDValidateHWProcPtr             validateHWProc;                /* Proc for driver to verify proper HW*/
  1108.     USBDInitializeDeviceProcPtr     initializeDeviceProc;        /* Proc that initializes the class driver.*/
  1109.     USBDInitializeInterfaceProcPtr     initializeInterfaceProc;    /* Proc that initializes a particular interface in the class driver.*/
  1110.     USBDFinalizeProcPtr             finalizeProc;                /* Proc that finalizes the class driver.*/
  1111.     USBDDriverNotifyProcPtr         notificationProc;            /* Proc to pass notifications to the driver.*/
  1112. };
  1113. typedef struct USBClassDriverPluginDispatchTable USBClassDriverPluginDispatchTable;
  1114. typedef USBClassDriverPluginDispatchTable * USBClassDriverPluginDispatchTablePtr;
  1115. /* Hub defines*/
  1116.  
  1117.  
  1118. enum {
  1119.     kUSBHubDescriptorType        = 0x29
  1120. };
  1121.  
  1122. enum {
  1123.                                                                 /* Hub features */
  1124.     kUSBHubLocalPowerChangeFeature = 0,
  1125.     kUSBHubOverCurrentChangeFeature = 1,                        /* port features */
  1126.     kUSBHubPortConnectionFeature = 0,
  1127.     kUSBHubPortEnablenFeature    = 1,
  1128.     kUSBHubPortSuspecdFeature    = 2,
  1129.     kUSBHubPortOverCurrentFeature = 3,
  1130.     kUSBHubPortResetFeature        = 4,
  1131.     kUSBHubPortPowerFeature        = 8,
  1132.     kUSBHubPortLowSpeedFeature    = 9,
  1133.     kUSBHubPortConnectionChangeFeature = 16,
  1134.     kUSBHubPortEnableChangeFeature = 17,
  1135.     kUSBHubPortSuspendChangeFeature = 18,
  1136.     kUSBHubPortOverCurrentChangeFeature = 19,
  1137.     kUSBHubPortResetChangeFeature = 20
  1138. };
  1139.  
  1140.  
  1141. enum {
  1142.     kHubPortConnection            = 1,
  1143.     kHubPortEnabled                = 2,
  1144.     kHubPortSuspend                = 4,
  1145.     kHubPortOverCurrent            = 8,
  1146.     kHubPortBeingReset            = 16,
  1147.     kHubPortPower                = 0x0100,
  1148.     kHubPortSpeed                = 0x0200
  1149. };
  1150.  
  1151. enum {
  1152.     kHubLocalPowerStatus        = 1,
  1153.     kHubOverCurrentIndicator    = 2,
  1154.     kHubLocalPowerStatusChange    = 1,
  1155.     kHubOverCurrentIndicatorChange = 2
  1156. };
  1157.  
  1158. enum {
  1159.     off                            = false,
  1160.     on                            = true
  1161. };
  1162.  
  1163.  
  1164.  
  1165. struct hubDescriptor {
  1166.                                                                 /* See usbDoc pg 250?? */
  1167.     UInt8                             dummy;                        /* to align charcteristics */
  1168.  
  1169.     UInt8                             length;
  1170.     UInt8                             hubType;
  1171.     UInt8                             numPorts;
  1172.  
  1173.     UInt16                             characteristics;
  1174.     UInt8                             powerOnToGood;                /* Port settling time, in 2ms */
  1175.     UInt8                             hubCurrent;
  1176.  
  1177.                                                                 /* These are received packed, will have to be unpacked */
  1178.     UInt8                             removablePortFlags[8];
  1179.     UInt8                             pwrCtlPortFlags[8];
  1180. };
  1181. typedef struct hubDescriptor            hubDescriptor;
  1182.  
  1183.  
  1184.  
  1185. #if PRAGMA_STRUCT_ALIGN
  1186.     #pragma options align=reset
  1187. #elif PRAGMA_STRUCT_PACKPUSH
  1188.     #pragma pack(pop)
  1189. #elif PRAGMA_STRUCT_PACK
  1190.     #pragma pack()
  1191. #endif
  1192.  
  1193. #ifdef PRAGMA_IMPORT_OFF
  1194. #pragma import off
  1195. #elif PRAGMA_IMPORT
  1196. #pragma import reset
  1197. #endif
  1198.  
  1199. #ifdef __cplusplus
  1200. }
  1201. #endif
  1202.  
  1203. #endif /* __USB__ */
  1204.  
  1205.